<template>
  <user-list-card :userList="userList"/>
  <van-empty v-if="flag" description="搜索结果为空"/>
</template>


<script setup>
import {ref} from "vue";
import UserListCard from "../component/userListCard.vue";
import {onMounted} from "vue";
import {recommendApi} from "../apis/userApi.js";
import {User} from "../pojo/User.js";
import router from "../router/index.js";

let userList = ref([])
let flag = ref(false)


onMounted(async () => {
  const resp = await recommendApi(1, 8)
  console.log(resp)
  if (resp.data.code === 40100) {   //40100错误码提示未登录
    router.push('/login')
  }

  if (resp.data.data?.records.size === 0) {
    flag.value = true
  } else {
    userList.value =
        resp.data?.data.records.map(
            user => {
              const newUser = new User()
              newUser.id = user.id
              newUser.username = user.username
              newUser.userAccount = user.userAccount
              newUser.avatarUrl = user.avatarUrl
              newUser.gender = user.gender
              newUser.phone = user.phone
              newUser.email = user.email
              newUser.userStatus = user.userStatus
              newUser.tags = JSON.parse(user.tags)    //字符串转换成数组
              newUser.isDelete = user.isDelete
              newUser.role = user.role
              newUser.userStatus = user.userStatus
              return newUser;
            }
        )
  }


})


</script>

<style scoped>

</style>